package br.com.FII.controller.assunto;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Stateless;

import br.com.FII.DAO.assunto.AssuntoRepository;
import br.com.FII.constants.ConstantesSistema;
import br.com.FII.controller.AbstractControllerImpl;
import br.com.FII.exception.CampoObrigatorioBranco;
import br.com.FII.model.Assunto;
import br.com.FII.utils.PropertiesUtil;

/**
 * Session Bean implementation class AssuntoController
 */
@Stateless
public class ControllerAssuntoImpl extends AbstractControllerImpl<Assunto> implements ControllerAssunto {

	@EJB
	private AssuntoRepository dao;

	@Override
	public void validarAssunto( Assunto as ) {
		if ( as.getAssunto().isEmpty() ) {
			throw new CampoObrigatorioBranco( PropertiesUtil.getProperty( ConstantesSistema.PROPERTIES_MESSAGES, "AssuntoEmBranco" ) );
		}

		if ( dao.existeAssunto( as ) ) {
			throw new CampoObrigatorioBranco( PropertiesUtil.getProperty( ConstantesSistema.PROPERTIES_MESSAGES, "AssuntoEmBranco" ) );
		}
	}

	@PostConstruct
	private void setDAO() {
		super.setAbstractRepository( dao );
	}


}
